package main

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type Person struct {
	Id   int    `gorm:"id"`
	Name string `gorm:"default:'defaultName'"`
	Sex  string `gorm:"default:'男'"`
	gorm.Model
}

func main() {
	dns := "root:root@tcp(127.0.0.1:3306)/userdb?charset=utf8mb4&parseTime=True&loc=Local"
	gormDB, err := gorm.Open(mysql.Open(dns), &gorm.Config{})
	if err != nil {
		fmt.Println("连接数据库失败Error：", err)
	}
	//gormDB.Migrator().CreateTable(&Person{})
	// person := &Person{
	// 	Name: "mmm",
	// 	Sex:  "女",
	// }
	//gormDB.Create(person)

	// person2 := map[string]interface{}{  //map形式插入数据后，相关的at时间不会自动插入
	// 	"Name": "ttt",
	// 	"Sex":  "女",
	// }
	// gormDB.Model(&Person{}).Create(&person2)

	//软删除
	gormDB.Where("id = ?", 4).Delete(&Person{})
	//真正删除
	gormDB.Unscoped().Where("id = ?", 5).Delete(&Person{})

}
